package com.chainwintel.prjmgmt.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
import javax.persistence.Version;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "userType")
public class User implements Serializable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -878385286956184244L;
	
	private long id;
	
	private String username;
	
	private String password;
	
//	private Set<Role> roles;
	
	private String userType;
	
	private Long version;
	
	private Set<MenuItem> operations ;

	@Id @GeneratedValue //(strategy = GenerationType.TABLE, generator = "hilo")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	
//	public void setRoles(Set<Role> roles) {
//		this.roles = roles;
//	}
//
//	@ManyToMany
//	public Set<Role> getRoles() {
//		return roles;
//	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	@Column(insertable = false,updatable = false)
	public String getUserType() {
		return userType;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(Long version) {
		this.version = version;
	}

	/**
	 * 用于保存“乐观锁”值
	 * the version field or property of this entity class that serves as its optimistic lock value.
	 * 
	 * @return the version
	 */
	@Version
	public Long getVersion() {
		return version;
	}

	/**
	 * @param operations the operations to set
	 */
	public void setOperations(Set<MenuItem> operations) {
		this.operations = operations;
	}

	/**
	 * @return the operations
	 */
	@ManyToMany
	public Set<MenuItem> getOperations() {
		return operations;
	}


	

}
